mod commands;
mod config_manager;

use tauri::Manager;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
            let _ = app
                .get_webview_window("main")
                .expect("no main window")
                .set_focus();
        }))
        .plugin(tauri_plugin_opener::init())
        .plugin(tauri_plugin_dialog::init())
        .setup(|app| {
            if cfg!(debug_assertions) {
                app.handle().plugin(
                    tauri_plugin_log::Builder::default()
                        .level(log::LevelFilter::Info)
                        .build(),
                )?;
            }

            let config_manager = config_manager::ConfigManager::new();
            // 将配置管理器添加到状态管理
            app.manage(config_manager);

            Ok(())
        })
        .invoke_handler(tauri::generate_handler![
            commands::open_source_homepage,
            commands::read_text_file,
            commands::load_map_config,
            commands::load_track_files,
            commands::load_user_data,
            commands::load_track_data,
            commands::load_visible_tracks,
            commands::delete_track_data,
            commands::save_current_path,
            commands::save_user_data,
            commands::save_track_data,
            commands::save_track_file,
            commands::save_snapshot_and_exit,
            commands::save_map_screenshot,
            commands::get_tianditu_route,
            commands::http_get,
            commands::open_photo_file,
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
